package com.qgy.springsecurity.models;

import com.alibaba.fastjson2.JSON;
import com.qgy.springsecurity.models.enums.ResultCode;

public class MyResult {

    private Boolean success;
    private ResultCode code;
    private String message;
    private Object data;

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public ResultCode getCode() {
        return code;
    }

    public void setCode(ResultCode code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    private MyResult() {}

    public static MyResult success() {
        MyResult myResult = new MyResult();
        myResult.setSuccess(true);
        myResult.setCode(ResultCode.SUCCESS);
        myResult.setMessage("请求成功");
        return myResult;
    }

    public static MyResult error() {
        MyResult myResult = new MyResult();
        myResult.setSuccess(false);
        myResult.setCode(ResultCode.ERROR);
        myResult.setMessage("请求成功");
        return myResult;
    }

    public MyResult code(ResultCode code) {
        this.code = code;
        return this;
    }

    public MyResult message(String message) {
        this.message = message;
        return this;
    }

    public MyResult data(Object data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
